package com.qianyu.project.mapper.provider.gs;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.ObjectUtils;

import java.util.Map;

/**
 * @author gs
 * @date create in 2021/1/31 10:20
 */
public class SubTenderPlanMapperProvider {

    public String selectPageList(IPage page, Map<String, String> params) {
        return new SQL() {
            {
                SELECT("stp.*,pi.project_name,pi.id as project_id,pt.type_name as project_type");
                FROM("sub_tender_plan stp,project_info pi,project_type pt");
                WHERE("stp.pro_id=pi.id and pt.type_id=pi.project_type");
                if (!ObjectUtils.isEmpty(params.get("projectName"))) {
                    WHERE("pi.project_name like '%${params.projectName}%'");
                }
                if (!ObjectUtils.isEmpty(params.get("planId"))) {
                    WHERE("stp.id like '%${params.planId}%'");
                }
                if (!ObjectUtils.isEmpty(params.get("planEditor"))) {
                    WHERE("stp.plan_editor like '%${params.planEditor}%'");
                }
                if (!ObjectUtils.isEmpty(params.get("approveStatus"))) {
                    WHERE("stp.approve_status = #{params.approveStatus}");
                }
                if (!ObjectUtils.isEmpty(params.get("projectType"))) {
                    WHERE("pt.type_id = #{params.projectType}");
                }
                if (!ObjectUtils.isEmpty(params.get("status"))) {
                    WHERE("stp.status=#{params.status}");
                }
            }
        }.toString();
    }
}
